package com.gitee.huanminabc.utils_tools.web_base.config;

import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ApiPrefixAutoConfiguration implements WebMvcConfigurer {
    @Value("${spring.application.prefix}")
    private String prefix;

    /**
     *
     * <p>
     * 增加restApi前缀   主要是为了隔离不同应用的接口
     * </p>
     *
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        if (Strings.isBlank(prefix) || prefix.equals("/")) {
            throw new RuntimeException("spring.application.prefix 不能为空或者为'/'");
        }
        configurer.addPathPrefix(prefix, c -> c.isAnnotationPresent(RestController.class));
    }

}